package com.example.rbacmanage.service.app.impl;

import com.example.rbacmanage.entity.app.MenuCoupon;
import com.example.rbacmanage.mapper.app.MenuCouponMapper;
import com.example.rbacmanage.service.app.MenuCouponService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class MenuCouponServiceImpl implements MenuCouponService {
    @Autowired
    private MenuCouponMapper menuCouponMapper;
    @Override
    public void save(MenuCoupon menuCoupon) {
        menuCoupon.setCreateTime(new Date());
        menuCouponMapper.insert(menuCoupon);
    }

    @Override
    public void remove(Long[] ids) {
        for (Long id : ids) {
            menuCouponMapper.del(id);
        }
    }

    @Override
    public void update(MenuCoupon menuCoupon) {
        menuCouponMapper.update(menuCoupon);
    }

    @Override
    public List<MenuCoupon> getAll(MenuCoupon menuCoupon) {
        return menuCouponMapper.list( menuCoupon );
    }

    @Override
    public PageInfo<MenuCoupon> getPage(MenuCoupon menuCoupon) {
        PageHelper.startPage(menuCoupon.getPage(),menuCoupon.getLimit());
        return new PageInfo<>(getAll(menuCoupon));
    }

    @Override
    public MenuCoupon getById(Long id) {
        return menuCouponMapper.queryOneById(id);
    }

    @Override
    public Integer getCount(MenuCoupon menuCoupon) {
        return menuCouponMapper.count(menuCoupon);
    }
}
